package com.it.gw.modules.station.adapter

import PictureVo
import android.graphics.drawable.Drawable
import android.util.Log
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.request.target.CustomTarget
import com.bumptech.glide.request.transition.Transition
import com.it.common.utils.GlideUtils
import java.io.File

class FileTarget(
    private val imageView: ImageView,
    private val vo: PictureVo,
    private val context: AppCompatActivity,
) : CustomTarget<File>() {
    companion object {
        const val TAG = "FileTarget"
    }

    override fun onResourceReady(resource: File, transition: Transition<in File>?) {
        // 文件下载完成，resource 是文件对象
        Log.d(TAG, "onResourceReady: $resource ")
        vo.filePath = resource.absolutePath
        context.runOnUiThread {
            GlideUtils.loadFile(context, resource.absolutePath, imageView)
        }

    }

    override fun onLoadCleared(placeholder: Drawable?) {
        // 清除资源
    }
}